import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { renderTag } from '#/utils/render';

export const designerModeOptions = [
  {
    label: '经典模式',
    value: 'CLASSICS',
  },
  {
    label: '仿钉钉模式',
    value: 'MIMIC',
  },
];

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'flowCode',
    label: '流程标识',
    hideLabel: true,
    componentProps: {
      placeholder: '请输入流程标识',
    },
  },
  {
    component: 'Input',
    fieldName: 'flowName',
    label: '流程名称',
    hideLabel: true,
    componentProps: {
      placeholder: '请输入流程名称',
    },
  },
];

export const columns: VxeGridProps['columns'] = [
  {
    align: 'center',
    type: 'checkbox',
    resizable: false,
    width: 45,
  },
  {
    field: 'flowCode',
    title: '流程标识',
    minWidth: 150,
    width: 150,
    showOverflow: true,
    slots: {
      default: ({ row }) => {
        return renderTag(row.flowCode || '标识异常', '#f50');
      },
    },
  },
  {
    field: 'flowName',
    title: '流程名称',
    minWidth: 150,
  },
  // {
  //   field: 'modelValue',
  //   title: '设计器模式',
  //   minWidth: 150,
  // },
  {
    field: 'version',
    title: '版本',
    align: 'center',
    minWidth: 80,
    width: 80,
    formatter: ({ cellValue }) => `V${cellValue}.0`,
  },
  {
    field: 'activityStatus',
    title: '流程设计器相关操作',
    align: 'center',
    minWidth: 200,
    width: 200,
    showOverflow: false,
    slots: {
      default: 'activityStatus',
    },
  },
  // {
  //   field: 'isPublish',
  //   title: '状态',
  //   align: 'center',
  //   minWidth: 80,
  //   width: 80,
  //   slots: {
  //     default: ({ row }) => {
  //       const cellValue = row.isPublish;
  //       return (
  //         <OptionsTag options={publishStatusOptions as any} value={cellValue} />
  //       );
  //     },
  //   },
  // },
  {
    field: 'action',
    fixed: 'right',
    align: 'center',
    slots: { default: 'action' },
    title: '操作',
    resizable: false,
    width: 'auto',
  },
];

export const modalSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'id',
  },
  {
    component: 'TreeSelect',
    fieldName: 'category',
    label: '流程分类',
    rules: 'selectRequired',
  },
  {
    component: 'Input',
    fieldName: 'flowCode',
    label: '流程标识',
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'flowName',
    label: '流程名称',
    rules: 'required',
  },
  {
    component: 'RadioGroup',
    fieldName: 'modelValue',
    label: '设计器模式',
    componentProps: {
      options: designerModeOptions,
      optionType: 'button',
      buttonStyle: 'solid',
    },
    defaultValue: 'CLASSICS',
    rules: 'selectRequired',
  },
  {
    component: 'Input',
    fieldName: 'formPath',
    label: '表单路径',
    rules: 'required',
  },
];
